/**
 * @param {number[]} nums
 * @return {number}
 */
 var reductionOperations = function(nums) {
    const n = nums.length
    let ans = 0
    nums.sort((a,b) => b-a)
    let i = 0
    while(nums[0] !== nums[n-1]){
        while(nums[i] === nums[i+1]) i++
        for(let j = 0; j<= i; j++){
            nums[j] = nums[i+1]
        }
        ans += (i+1)
    }
    return ans
};